//
//  PDFShowAlertPlugin.m
//  PCDBankSix
//
//  Created by APPLE on 2023/8/23.
//

#import "PDFShowAlertPlugin.h"
#import "YTOpenFIleAlertView.h"

@implementation PDFShowAlertPlugin

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback{
    
    NSDictionary *dictData = (NSDictionary *)data;
    NSString *strCallback = dictData[@"success"];
    NSString *fileUrl = dictData[@"url"];
    NSString *title = dictData[@"title"];
    NSString *readType = dictData[@"readType"];
    NSString *confirmText = [dictData objectForKey:@"confirmText"];
    NSString *cancelText= [dictData objectForKey:@"cancelText"];
    NSString *maxSeconds = [dictData objectForKey:@"maxSeconds"];
    
    //PDF弹窗
    YTOpenFIleAlertView *alertView = [[YTOpenFIleAlertView alloc]initWithTitle:title
                                                                       fileUrl:fileUrl
                                                                      readType:[readType integerValue]
                                                                firstItemTitle:[PCDUtil nilOrEmptyString:cancelText]?@"否":cancelText
                                                               secondItemTitle:[PCDUtil nilOrEmptyString:confirmText]?@"是":confirmText
                                                                   cancleBlock:^{
        NSDictionary *dic = @{
                               @"confirm":@(NO),
                               @"cancel":@(YES)
                               };
        evaluateJavaScriptOnMainThread(self, strCallback, [dic JSONRepresentation]);
    }
                                                                  confirmBlock:^{
        NSDictionary *dic = @{
                               @"confirm":@(YES),
                               @"cancel":@(NO)
                               };
        evaluateJavaScriptOnMainThread(self, strCallback, [dic JSONRepresentation]);
    }];
    if (![PCDUtil nilOrEmptyString:maxSeconds]) {
        alertView.maxSeconds = [maxSeconds integerValue];
    }
    [alertView show];
}

@end
